package com.nanfang51g3.ckz.http;

import com.nanfang51g3.ckz.domain.AccountingBean;
import com.nanfang51g3.ckz.domain.DealBean;
import com.nanfang51g3.ckz.domain.DownloadBean;
import com.nanfang51g3.ckz.domain.HttpResultBean;
import com.nanfang51g3.ckz.domain.HttpResultBeans;
import com.nanfang51g3.ckz.domain.IndexBean;
import com.nanfang51g3.ckz.domain.MoneyDetailBean;
import com.nanfang51g3.ckz.domain.NewProject;
import com.nanfang51g3.ckz.domain.PatchBean;
import com.nanfang51g3.ckz.domain.ShareBean;
import com.nanfang51g3.ckz.domain.SuccessBean;
import com.nanfang51g3.ckz.domain.UserBean;

import java.util.List;
import java.util.Map;

import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;
import rx.Observable;

/**
 * Created by Administrator on 2016/4/12.
 */
public interface RestApi {
    //        String BASE_URL = "http://192.168.2.138/ckt.51g3.com/";
    String BASE_URL = "http://ckt.51g3.com/";
//    String BASE_URL = "http://192.168.1.51:9999/sysapp/";
//String BASE_URL = "https://kyfw.12306.cn/";
//    String BASE_URL = "https://www.nearby.ren:8080/MccServer/";
    @GET("otn")
    Call<ResponseBody> Https12306();


    @GET("requestIndex")
    Call<ResponseBody> testServer();



    /**
     * 2.1注册发送验证码
     *
     * @param phone
     * @return
     */
    @FormUrlEncoded
    @POST("register.php?act=sendcode")
    Observable<HttpResultBean<SuccessBean>> registerSendcode(@Field("phone") String phone, @Field("sign") String sign);


    /**
     * 2.2注册验证验证码
     *
     * @param phone
     * @return
     */
    @FormUrlEncoded
    @POST("register.php?act=verifycode")
    Observable<HttpResultBean<SuccessBean>> registerVerifycode(@Field("code") String code, @Field("phone") String phone, @Field("sign") String sign);

    /**
     * 2.3注册
     *
     * @param username
     * @param password
     * @param rid
     * @param sign
     * @return
     */
    @FormUrlEncoded
    @POST("register.php")
    Observable<HttpResultBean<UserBean>> register(@Field("phone") String username, @Field("password") String password, @Field("rid") String rid, @Field("sign") String sign);

    /**
     * 2.4登录
     *
     * @param username
     * @param password
     * @param sign
     * @return
     */
    @FormUrlEncoded
    @POST("login.php")
    Observable<HttpResultBean<UserBean>> login(@Field("phone") String username, @Field("password") String password, @Field("sign") String sign);

    /**
     * 2.5获取用户信息数据
     *
     * @param userid
     * @param sign
     * @return
     */
    @GET("userinfo.php")
    Observable<HttpResultBean<UserBean>> userinfo(@Query("userid") String userid, @Query("sign") String sign);

    /**
     * 2.6修改密码
     *
     * @param userid
     * @param oldpass
     * @param password
     * @param sign
     * @return
     */
    @FormUrlEncoded
    @POST("repass.php")
    Observable<HttpResultBean<SuccessBean>> repass(@Field("userid") String userid, @Field("oldpass") String oldpass, @Field("password") String password, @Field("sign") String sign);


    /**
     * 2.7忘记密码发送验证码
     *
     * @param phone
     * @param sign
     * @return
     */
    @FormUrlEncoded
    @POST("forgetpass.php?act=sendcode")
    Observable<HttpResultBean<SuccessBean>> forgetpassSendcode(@Field("phone") String phone, @Field("sign") String sign);


    /**
     * 2.8忘记密码验证验证码
     *
     * @param code
     * @param phone
     * @param sign
     * @return
     */
    @FormUrlEncoded
    @POST("forgetpass.php?act=verifycode")
    Observable<HttpResultBean<SuccessBean>> forgetpassVerifycode(@Field("code") String code, @Field("phone") String phone, @Field("sign") String sign);


    /**
     * 2.9忘记密码重设密码
     *
     * @param phone
     * @param sign
     * @return
     */
    @FormUrlEncoded
    @POST("forgetpass.php")
    Observable<HttpResultBean<SuccessBean>> forgetpass(@Field("phone") String phone, @Field("password") String password, @Field("sign") String sign);


    /**
     * *   *   *   *   *   *  2.10修改资料 *   *   *   *   *   *   *   *   *   *  start
     */

    @FormUrlEncoded
    @POST("reuserinfo.php")
    Observable<HttpResultBean<UserBean>>
    reuserinfoUserNmae(
            @Field("userid") int userid,
            @Field("username") String username,
            @Field("sign") String sign
    );

    @FormUrlEncoded
    @POST("reuserinfo.php")
    Observable<HttpResultBean<UserBean>>
    reuserinfoEmail(
            @Field("userid") int id,
            @Field("email") String email,
            @Field("sign") String sign
    );

    @FormUrlEncoded
    @POST("reuserinfo.php")
    Observable<HttpResultBean<UserBean>>
    reuserinfoQQ(
            @Field("userid") int userid,
            @Field("qq") String qq,
            @Field("sign") String sign
    );

    @FormUrlEncoded
    @POST("reuserinfo.php")
    Observable<HttpResultBean<UserBean>>
    reuserinfoRealName(
            @Field("userid") String userid,
            @Field("real_name") String real_name,
            @Field("sign") String sign);

    @FormUrlEncoded
    @POST("reuserinfo.php")
    Observable<HttpResultBean<UserBean>>
    reuserinfoBankName(
            @Field("userid") String userid,
            @Field("bank") String bank,
            @Field("sign") String sign);


    @FormUrlEncoded
    @POST("reuserinfo.php")
    Observable<HttpResultBean<UserBean>>
    reuserinfoBankCard(
            @Field("userid") String userid,
            @Field("bank_card") String bank_card,
            @Field("sign") String sign);


    @FormUrlEncoded
    @POST("reuserinfo.php")
    Observable<HttpResultBean<UserBean>>
    reuserinfoAliPay(
            @Field("userid") String userid,
            @Field("alipay") String alipay,
            @Field("sign") String sign);

    /**
     *  *   *   *   *   *   *  2.10修改资料 *   *   *   *   *   *   *   *   *   * end
     *
     */
    /**
     * /* *
     * 二进制流上传方式 https://github.com/square/retrofit/issues/1063
     *
     * @param dynamic
     * @param photo
     * @return
     * @POST("trip/{tripId}/media/photos") Call<MediaPost> postEventPhoto(
     * @Path("eventId") int tripId,
     * @Header("Authorization") String accessToken,
     * @Query("direction") String direction,
     * @Body RequestBody photo);
     * Caller
     * InputStream in = new FileInputStream(new File(media.getPath()));
     * byte[] buf;
     * buf = new byte[in.available()];
     * while (in.read(buf) != -1);
     * RequestBody requestBody = RequestBody
     * .create(MediaType.parse("application/octet-stream"), buf);
     * Call<MediaPost> mediaPostCall = tripApiService.postTripPhoto(
     * tripId,
     * ((GlobalInfo) getApplicationContext()).getApiAccessToken(),
     * direction,
     * requestBody);
     */
//    @POST("userpic.php")
//    Observable<HttpResultBean<SuccessBean>> userpic(@QueryMap Map<String, String> dynamic,
//                                                    @Body RequestBody photo);
    @Multipart
    @POST("userpic.php")
    Observable<HttpResultBean<SuccessBean>> userpic(@QueryMap Map<String, String> dynamic,
                                                    @Part("file\"; filename=\"pp.png\" ") RequestBody photo);

    /**
     * 3.1获取可接推广列表
     *
     * @param page
     * @param limit
     * @param sign
     * @return
     */
    @GET("list.php")
    Observable<HttpResultBean<List<IndexBean>>> list(
            @Query("page") int page, @Query("limit") int limit, @Query("sign") String sign);


    /**
     * 3.1获取可接推广列表
     *
     * @param page
     * @param limit
     * @param sign
     * @return
     */
    @GET("list.php")
    Observable<HttpResultBean<List<IndexBean>>> listtnaem(@Query("page") int page, @Query("limit") int limit, @Query("sign") String sign, @Query("tname") String tname);

    /**
     * 3.1获取可接推广列表
     *
     * @param page
     * @param limit
     * @param sign
     * @return
     */
    @GET("list.php")
    Observable<HttpResultBean<List<IndexBean>>> list(@Query("page") int page, @Query("limit") int limit, @Query("sign") String sign, @Query("city") String city);


    @GET("SysAppController/delegateHandleRequest")
    Observable<HttpResultBeans<List<NewProject>>> OPT(
            @Query("OPT") String OPT);

    /**
     * 3.1获取可接推广列表
     *
     * @param page
     * @param limit
     * @param sign
     * @return
     */
    @GET("list.php")
    Observable<HttpResultBean<List<IndexBean>>> list(@Query("page") int page, @Query("limit") int limit, @Query("sign") String sign, @Query("city") String city, @Query("tname") String tname);

    /**
     * 3.2获取用户已分享的推广收益流水
     *
     * @param page
     * @param limit
     * @param userid
     * @param sign
     * @return
     */
    @GET("adlist.php")
    Observable<HttpResultBean<List<AccountingBean>>> adList(@Query("page") int page, @Query("limit") int limit, @Query("userid") String userid, @Query("sign") String sign);


    /**
     * 3.3获取用户已分享的推广收益流水
     *
     * @param page
     * @param limit
     * @param userid
     * @param sign
     * @return
     */
    @GET("adlist.php")
    Observable<HttpResultBean<List<AccountingBean>>> accounting(@Query("page") int page, @Query("limit") int limit, @Query("aid") String aid, @Query("userid") String userid, @Query("sign") String sign);

    /**
     * 4.1用户申请提现
     *
     * @param userid
     * @param type
     * @param total
     * @return
     */
    @FormUrlEncoded
    @POST("deal.php")
    Observable<HttpResultBean<DealBean>> deal(@Field("userid") String userid, @Field("type") String type, @Field("total") String total, @Field("sign") String sign);


    /**
     * 4.2用户提现列表
     *
     * @param userid
     * @param page
     * @param limit
     * @return
     */
    @GET("deallist.php")
    Observable<HttpResultBean<List<MoneyDetailBean>>> deallist(@Query("userid") String userid, @Query("page") String page, @Query("limit") String limit, @Query("sign") String sign);


    /**
     * 获取分享Url
     *
     * @param aid
     * @param userid
     * @param sign
     * @return
     */
    @FormUrlEncoded
    @POST("view.php")
    Observable<HttpResultBean<ShareBean>> shareUrlView(
            @Field("aid") String aid,
            @Field("userid") String userid,
            @Field("sign") String sign);


    /**
     * 提交APP日志崩溃信息
     *
     * @param version
     * @param builddate
     * @param creatdate
     * @param device
     * @param trace
     * @param sign
     * @return
     */
    @FormUrlEncoded
    @POST("logexception.php")
    Observable<HttpResultBean<String>> appLogException(
            @Field("version") String version,
            @Field("builddate") String builddate,
            @Field("creatdate") String creatdate,
            @Field("device") String device,
            @Field("trace") String trace,
            @Field("sign") String sign);

    /**
     * 获取APP日志崩溃信息
     *
     * @param act
     * @param time
     * @param sign
     * @return
     */
    @FormUrlEncoded
    @POST("logexception.php")
    Observable<HttpResultBean<String>> appLogException(
            @Field("act") String act,
            @Field("time") String time,
            @Field("sign") String sign);


    /**
     * 是否存在更新补丁[暂未使用]
     *
     * @return
     */
    @FormUrlEncoded
    @POST("androidapp.php")
    Observable<HttpResultBean<PatchBean>> isDownloadAPatch(@Field("app_v") String aPatch, @Field("sign") String sign);


    @FormUrlEncoded
    @POST("androidfile.php")
    Call<ResponseBody> downloadAppAPatch(@Field("app_v") String aPatch, @Field("sign") String sign);

    /**
     * apk识别版本更新
     *
     * @param versioncode
     * @param versionname
     * @return
     */
    @FormUrlEncoded
    @POST("androidapk.php")
    Observable<HttpResultBean<DownloadBean>> isDownloadApk(@Field("versioncode") String versioncode, @Field("versionname") String versionname);

    /**
     * apk下载版本
     *
     * @return
     */
    @GET("download.php?")
    Call<ResponseBody> downloadApk(@QueryMap Map<String, String> dynamic);
//    http://ckt.51g3.com/download.php?type=android.apk

    //    @GET("requestIndex")
//    Observable<ArrayList<ReleaseInfo>> requestIndex();
//
    @GET("images/avater/new-ca2fedc5f82942d8c2b66157be866e6c.apatch")
    Call<ResponseBody> downloadFileWithFixedUrl();

    @GET("images/avater/new-ca2fedc5f82942d8c2b66157be866e6c.apatch")
    Observable<ResponseBody> cancel();


}
